package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * ClassName: OrderMapper
 * Package: com.sky.mapper
 * Description:
 *
 * @Author 那啥啥
 * @Create 2024/3/19  15:25
 * @Version 1.0
 */
@Mapper
public interface OrderMapper  {
    void insert(Orders orders);



    /**
     * 根据订单号查询订单
     * @param orderNumber
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

    /**
     * f分页查询历史订单
     * @param ordersPageQueryDTO
     * @return
     */
    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
     * 根据id查询订单号
     * @param id
     * @return
     */

    @Select("select number from orders where id = #{id}")
    Orders getNumberById(Long id);

    /**
     * 根据id查询订单
     * @param id
     * @return
     */
    @Select("select *from orders where id = #{id}")
    Orders getById(Long id);

    /**
     * 根据状态统计订单数量
     * @param status
     */
    @Select("select count(id) from orders where status = #{status}")
    Integer countStatus(Integer status);


    /**
     * 根据实践和订单状态查询
     */
    @Select("select *from orders where status =#{status} and order_time < (#{orderTime})")
    List<Orders>  getByStatusAndOrderTimeLT(Integer status, LocalDateTime orderTime);

    /**
     * 查询每天的营业额
     * @param map
     * @return
     */
    Double sumByMap(Map map);

@Select("select count(*) from  orders where order_time > #{beginTime} and order_time < #{endTime}")
    Integer getByDate(LocalDateTime beginTime, LocalDateTime endTime);
@Select("select count(*) from  orders where order_time > #{beginTime} and order_time < #{endTime} and status = #{completed}")
    Integer getByDateAndStatus(LocalDateTime beginTime, LocalDateTime endTime, Integer completed);

    List<GoodsSalesDTO> getTop10(LocalDateTime beginTime, LocalDateTime endTime);

    /**
     * 查询订单数
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}
